package api

import (
	"api-gateway/basic/global"
	__ "api-gateway/basic/proto"
	"api-gateway/handler/dto"
	"github.com/gin-gonic/gin"
	"net/http"
)

func VideoList(c *gin.Context) {
	var req = dto.VideoListReq{}
	if err := c.ShouldBindQuery(&req); err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  "参数错误",
		})
		return
	}

	list, err := global.VideoClient.VideoList(c, &__.VideoListReq{
		TitleKeyword: req.TitleKeyword,
		MinPlayCount: int64(req.MinPlayCount),
		AreaName:     req.AreaName,
		TypeName:     req.TypeName,
		ChannelName:  req.ChannelName,
		PayTypeName:  req.PayTypeName,
		SortBy:       req.SortBy,
		SortOrder:    req.SortOrder,
		Page:         int64(req.Page),
		Size:         int64(req.Size),
	})

	if err != nil {
		c.JSON(http.StatusBadRequest, gin.H{
			"code": 400,
			"msg":  err.Error(),
		})
		return
	}

	c.JSON(http.StatusOK, gin.H{
		"code": 200,
		"msg":  "查询成功",
		"data": list,
	})
}
